package com.zhiliao.chain.demo3;

/**
 * @author zouxf
 * @date 2023/8/29 9:04
 * @description
 */
public class Pipleline {

    private ChannelContextHandler head = new ChannelContextHandler(new AbstractHandler() {
        @Override
        protected void doHandler(ChannelContextHandler handler, Object arg0) {
            handler.executeNext(arg0);
        }
    });

    public void addLast(AbstractHandler handler) {
        ChannelContextHandler next = head;
        while (next.getNext() != null) {
            next = next.getNext();
        }
        next.setNext(new ChannelContextHandler(handler));
    }

    public void execute(Object arg0) {
        this.head.doHandler(arg0);
    }
}
